using System;
using System.Management;
using System.Net;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;

public class GetHardwareInfoClass
{
	public static string GetHardwareHash()
	{
		MD5CryptoServiceProvider mD5CryptoServiceProvider = new MD5CryptoServiceProvider();
		string text = BitConverter.ToString(mD5CryptoServiceProvider.ComputeHash(Encoding.Default.GetBytes(UUID() + 获取本机网卡物理地址())));
		text = text.Replace("-", "");
		return text.ToLower();
	}

	public static string UUID()
	{
		try
		{
			ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystemProduct");
			string result = null;
			using (ManagementObjectCollection.ManagementObjectEnumerator managementObjectEnumerator = managementObjectSearcher.Get().GetEnumerator())
			{
				if (managementObjectEnumerator.MoveNext())
				{
					ManagementObject managementObject = (ManagementObject)managementObjectEnumerator.Current;
					result = managementObject["UUID"].ToString().Trim();
				}
			}
			return result;
		}
		catch
		{
			return "unknow";
		}
	}

	public static string 获取本机网卡物理地址()
	{
		string result = "";
		try
		{
			ManagementClass managementClass = new ManagementClass("Win32_NetworkAdapterConfiguration");
			foreach (ManagementObject instance in managementClass.GetInstances())
			{
				if (instance["IPEnabled"].ToString() == "True")
				{
					result = instance["MacAddress"].ToString();
				}
			}
			return result;
		}
		catch
		{
			return "unknow";
		}
	}

	public static string 获取本机IP地址()
	{
		try
		{
			return Dns.GetHostEntry(Dns.GetHostName()).AddressList[0].ToString();
		}
		catch
		{
			return "127.0.0.1";
		}
	}

	[DllImport("kernel32.dll")]
	private static extern int GetVolumeInformation(string A_0, string A_1, int A_2, ref int A_3, int A_4, int A_5, string A_6, int A_7);
}
